# -*- coding:UTF-8 -*-
import requests
import json

timeout_default = 3

headers = {
    "Content-Type": "application/json;charset=UTF-8",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.50"
    }


def get(url:str, data:dict, timeout=3) -> dict:
    try:
        timeout = timeout if timeout else timeout_default
        timeout = timeout if timeout else 3
        response = requests.get(url=url, params=data, headers=headers, timeout=timeout, verify=False)
        return json.loads(response.text)
    except Exception as e:
        print(e)
    return None


def post(url:str, data:dict, timeout=3) -> dict:
    try:
        timeout = timeout if timeout else timeout_default
        timeout = timeout if timeout else 3
        data = json.dumps(data)
        response = requests.post(url=url, data=data, headers=headers, timeout=timeout, verify=False)
        return json.loads(response.text)
    except Exception as e:
        print(e)
    return None


def put(url:str, data:dict, timeout=3) -> dict:
    try:
        timeout = timeout if timeout else timeout_default
        timeout = timeout if timeout else 3
        data = json.dumps(data)
        response = requests.put(url, data=data, headers=headers, timeout=timeout, verify=False)
        results = json.loads(response.text)
        return results
    except Exception as e:
        print(e)
    return None


def delete(url:str, data:dict, timeout=3) -> dict:
    try:
        timeout = timeout if timeout else timeout_default
        timeout = timeout if timeout else 3
        data = json.dumps(data)
        response = requests.delete(url, data=data, headers=headers, timeout=timeout, verify=False)
        results = json.loads(response.text)
        return results
    except Exception as e:
        print(e)
    return None